﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>双击单元格变为可编辑</title>
    <script type="text/javascript">
        function editCell(obj){
            if(obj.innerText==""){
                obj.innerHTML="<input value='' onblur='update(this.value)'>";               //插入输入框，失去焦点时更新
            }else{
                obj.innerHTML="<input value="+obj.innerText+" onblur='update(this.value)'>";//插入文本框，且指定内容
            }
        }
        
        function update(txt){
            document.getElementById("Td2").innerText = txt;
        }
    </script>
    
</head>
<body>
<table border="1">
    <tr>
        <td id="Td2" onDblClick="editCell(this)">第一行第一列</td>
    </tr>
</table>
</body>
</html>